package com.example.panda.mine;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.panda.R;
import com.example.panda.service.ChatActivity;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.List;

public class RecyclerActivity extends Activity {


    List<list> mListItem;
    RecyclerView mRrecyclerView;
    Context context;
    JSONArray mNetdata;

    int tp[] = {R.drawable.diary,R.drawable.attention,R.drawable.issue,R.drawable.collect,R.drawable.service};
    int tv[] = {R.string.diary,R.string.attention,R.string.issue,R.string.collect,R.string.service};
    int tp1[] = {R.drawable.more,R.drawable.more,R.drawable.more,R.drawable.more,R.drawable.more};





    @Override
    protected void onCreate(Bundle save) {
        super.onCreate(save);
        setContentView(R.layout.recycler_mian);

        mRrecyclerView = findViewById(R.id.recycler);

        mListItem = new ArrayList<>();
        Data();

        mRrecyclerView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(context, ChatActivity.class);
                startActivity(intent1);
            }
        });

        }



    private void Data(){
        int kk[] = {View.GONE,View.GONE,View.GONE,View.VISIBLE,View.GONE,View.GONE,View.GONE,View.VISIBLE,View.GONE,View.GONE,View.GONE,View.VISIBLE};
                        for (int i = 0; i < 6; i++) {
                            try {

                                list listitem = new list(tv[i],tp[i],tp1[i],kk[i]);
                                mListItem.add(listitem);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        initRecyclerView(mListItem);

    }

    private void initRecyclerView(List list){
        RecyclerAdapter recyclerAdapter = new RecyclerAdapter(this,list,onItemClickListener);
        mRrecyclerView.setLayoutManager(new GridLayoutManager(this,1));
        mRrecyclerView.setAdapter(recyclerAdapter);


    }

    private OnItemClickListener onItemClickListener = new OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Toast.makeText(RecyclerActivity.this," 点击了 "+position,Toast.LENGTH_SHORT).show();
        }
    };

}
